package com.seocoo.worker.base.widget;

import android.content.Context;
import android.support.annotation.Nullable;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;

import com.seocoo.worker.R;
import com.seocoo.worker.base.widget.adapter.BaseImageUpLoadAdapter;
import com.seocoo.worker.base.widget.rsp.RspImg;

import java.util.List;

public class BaseImageUpLoadView extends LinearLayout {

    private RecyclerView recyclerView;
    private BaseImageUpLoadAdapter adapter;

    public BaseImageUpLoadView(Context context) {
        super(context);
    }

    public BaseImageUpLoadView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public BaseImageUpLoadView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    private void initView(Context context) {
        View view = inflate(context, R.layout.base_image_upload_layout, null);
        recyclerView = view.findViewById(R.id.recycler_view);
        recyclerView.setLayoutManager(new GridLayoutManager(context, 3));
    }

    public void setArrowImageCount(int count) {
        recyclerView.setLayoutManager(new GridLayoutManager(this.getContext(), count));
        adapter = new BaseImageUpLoadAdapter();
        RspImg rspImg = new RspImg();
        rspImg.setImgUrl(null);
        rspImg.setImgTag("初始化选择的图片");
        List<RspImg> data = adapter.getData();
        data.add(rspImg);
        adapter.setNewData(data);
        recyclerView.setAdapter(adapter);
    }

    /**
     * 新增图片
     *
     * @param url 新的图片地址
     */
    public void addImageData(String url) {

    }

    /**
     * 更换图片
     *
     * @param position 当前编辑图片位置
     * @param url      新的图片地址
     */
    public void editImageData(int position, String url) {

    }
}
